﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace University
{
    class Course
    {
        private string name;
        private Dictionary<int, Student> students;

        public Course(string name)
        {
            this.Name = name;
            students = new Dictionary<int, Student>();
        }

        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("Name can not be null!");
                }
                this.name = value;
            }
        }

        public List<Student> Students 
        {
            get
            {
                return this.students.Values.ToList();
            }
        }

        public void AddStudent(Student student)
        {
            if(this.students.Count == 29)
            {
                throw new Exception("The course is already full and no more students can be added!");
            }
            if (students.ContainsKey(student.FN))
            {
                throw new ArgumentException(String.Format(
                    "The course already contains a student with fn: {0}!", student.FN));
            }
            students.Add(student.FN, student);
        }

        public void RemoveStudentByFN(int fn)
        {
            bool studentRemoved = students.Remove(fn);
            if (!studentRemoved)
            {
                throw new ArgumentException(String.Format(
                    "The student with fn: {0} is not attending this course and can not be removed!", fn));
            }
        }
    }
}
